<?php

//判断是否登录
class CheckAction extends Action{
	//判断SESSION是否超时
	public function _initialize() {
		$module = strtolower(MODULE_NAME);
		$action = strtolower(ACTION_NAME);
		
		if($module=='console') {
			//以下这些不需要验证是否登录
			if($action!='login' && $action!='xianshi') {
				if(session('?se')) {
					if(session('se') < time()) {
						session('admin',null);
						session('se',null);
						$this->redirect('console/login');
					}else{
						session('se', time()+C('SESSION_TIME_OUT'));
					}
				}else{
					$this->redirect('console/login');
				}
			}
		}
	}
	
	
	//判断是否有权限
	function check_auth($need) {
		$auth = session('admin.authority');
		if(!empty($auth)) {
			if(in_array('admin',$auth) || in_array($need,$auth)) {
				return true;
			} else {
				return false;
			}
		} else {
			return false;
		}
	}
	
	
	//无权限则跳转到无权提示页面
	function need_auth($need) {
		if(!$this->check_auth($need)) {
			$this->display('console:noright');
			exit();
		}
	}
	
	
}


?>